﻿using System;
using System.Reflection;

namespace Caramel.Entities.Testing
{
	//public class SimpleProperty<T, TProperty> : Property<T, TProperty> where T : class, IEntity, new()
	//{
	//    public SimpleProperty(PropertyInfo member, Func<TProperty, TProperty, bool> comparer)
	//        : base(member, comparer)
	//    {
	//    }

	//    public override void CheckValue(T expected, T actual)
	//    {
	//        var expectedValue = this.GetValue(expected) as T;
	//        var actualValue = this.GetValue(actual) as T;

	//        if (!this.Comparer(expectedValue, actualValue))
	//        {
	//            throw new ApplicationException(String.Format("For {0} expected {1} but got {2}.", this.Name, expectedValue, actualValue));
	//        }
	//    }
	//}

	public class SimpleProperty<T, TProperty> : Property<T, TProperty> where T : class, IEntity, new()
	{
		public SimpleProperty(PropertyInfo member, Func<TProperty, TProperty, bool> comparer)
			: base(member, comparer)
		{
		}

		public override void CheckValue(T expected, T actual)
		{
			var expectedValue = (TProperty)this.GetValue(expected);
			var actualValue = (TProperty)this.GetValue(actual);

			if (!this.Comparer(expectedValue, actualValue))
			{
				throw new ApplicationException(String.Format("For {0} expected {1} but got {2}.", this.Name, expectedValue, actualValue));
			}
		}
	}
}
